package blackeagle.ems;

/**
 * A class containing various input validation methods.
 */
public final class InputValidator {
    private InputValidator(){}
    
    /**
     * Validates a department name.
     * @param name the name.
     * @return <code>null</code> if the name is well formatted; otherwise a message describing the error.
     */
    public static String validateDepartmentName(String name){
        /**
         * A regex pattern allowing only Letters A-Z (and ÅÄÖ). Ignores case.
         */
        final String pattern = "(?i)^([a-zåäö\\s]+)$";
       
        if(!name.matches(pattern)){
            if(name.length()==0){
                return "You must enter a name.";          
            }else{
                return "You may only use letters in the name.";
            }
        }
        
        return null;
    }
    
    /**
     * Validates a domain name
     * @param name the name.
     * @return <code>null</code> if the name is well formatted; otherwise a message describing the error.
     */
    public static String validateDomainName(String name){
        /**
         * A regex pattern allowing only Letters A-Z (and ÅÄÖ). Ignores case.
         */
        final String pattern = "(?i)^([a-zåäö\\s]+)$";
        
       
        if(!name.matches(pattern)){
            if(name.length()==0){
                return "You must enter a name.";          
            }else{
                return "You may only use letters in the name.";
            }
        }
        
        return null;
    }
    
    /**
     * Validates a game name
     * @param name the name.
     * @return <code>null</code> if the name is well formatted; otherwise a message describing the error.
     */
    public static String validateGameName(String name){
        final String pattern = "(?i)^([\\w]+)$";
        
        if(!name.matches(pattern)){
            if(name.length()==0){
                return "You must enter a name.";
            }else{
                return "You have used invalid characters.";
            }
        }
        
        return null;
    }
}
